home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / HyperCuber Source / HyperCuber 2.0 Source.sit / HyperCuber 2.0 Source / CHyperScrollBar.cp < prev    next >
Text File  |  1994-04-13  |  6KB  |  192 lines

  1. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. //| CHyperScrollBar.cp
  3. //|
  4. //| This implements a scroll bar which has "live" thumb tracking, and wraps around
  5. //|_______________________________________________________________________________________
  6.  
  7. #include "CHyperScrollBar.h"
  8.  
  9.  
  10.  
  11. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  12. //| CHyperScrollBar::IHyperScrollBar
  13. //|
  14. //| Purpose: Initialize the scroll bar.
  15. //|
  16. //| Parameters: scroll_bar: scroll bar to track
  17. //|             wrap:       TRUE if the bar should wrap around
  18. //|             rest same as superclass
  19. //|____________________________________________________________
  20.  
  21. void CHyperScrollBar::IHyperScrollBar(CView *enclosure, CBureaucrat *supervisor,
  22.                                         Orientation orientation, short length,
  23.                                         short horiz, short vert, Boolean wrap)
  24. {
  25.  
  26.     CScrollBar::IScrollBar(enclosure, supervisor,        //  Initialize superclass
  27.                             orientation, length,
  28.                             horiz, vert);
  29.  
  30.     SetCRefCon(macControl, 0L);                            //  This may be replaced by a handle if
  31.                                                         //    the bar is linked to something
  32.     
  33.     fWrap = wrap;                                        //  Remember whether to wrap
  34.     
  35. }    //==== CHyperScrollBar::IHyperScrollBar() ====\\
  36.  
  37.  
  38.  
  39. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  40. //| CHyperScrollBar::Dispose
  41. //|
  42. //| Purpose: Dispose of the scroll bar.
  43. //|
  44. //| Parameters: none
  45. //|_________________________________________________________
  46.  
  47. void CHyperScrollBar::Dispose(void)
  48. {
  49.  
  50.     Handle handle = (Handle) GetCRefCon(macControl);    //  Get rid of the refcon handle, if any
  51.     if (handle)
  52.         DisposeHandle(handle);
  53.         
  54.     CScrollBar::Dispose();                                //  Dispose of superclass
  55.     
  56. }    //==== CHyperScrollBar::Dispose() ====\\
  57.  
  58.  
  59.  
  60. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  61. //| CHyperScrollBar::SetValue
  62. //|
  63. //| Purpose: Set the value of the scroll bar.  Unlike normal scroll bars, this
  64. //|          wraps around.  So if the value is greater than the max, it is
  65. //|          wrapped to the min.
  66. //|
  67. //| Parameters: value: the value to set
  68. //|____________________________________________________________________________
  69.  
  70. void CHyperScrollBar::SetValue(short value)
  71. {
  72.  
  73.     if (fWrap)
  74.         {
  75.         short max = GetMaxValue();
  76.         short min = GetMinValue();
  77.         
  78.         if (value > max)                        //  Allow wrap-around
  79.             SetValue(value - (max - min));
  80.     
  81.         else if (value < min)
  82.             SetValue(value + (max - min));
  83.         
  84.         else
  85.             CScrollBar::SetValue(value);        //  Set the value
  86.         }
  87.     else
  88.         CScrollBar::SetValue(value);            //  Set the value, no wrap-around
  89.  
  90. }    //==== CHyperScrollBar::SetValue() ====\\
  91.  
  92.  
  93.  
  94. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  95. //| CHyperScrollBar::DoClick
  96. //|
  97. //| Purpose: This is called when the control is clicked (this code taken partly
  98. //|          from TCL CControl::DoClick).
  99. //|
  100. //| Parameters: value: the value to set
  101. //|____________________________________________________________________________
  102.  
  103. void CHyperScrollBar::DoClick(
  104.     Point        hitPt,                    /* Mouse location in Frame coords    */
  105.     short        modifierKeys,            /* State of modifier keys            */
  106.     long        when)                    /* Tick time of mouse click            */
  107. {
  108.     register short    whichPart;            /* Part of control clicked in        */
  109.     short            origValue;            /* Original control setting            */
  110.     short            delta;                /* Change in control setting        */
  111.     LongPt            tmp;
  112.     
  113.     QDToLongPt( hitPt, &tmp);
  114.     FrameToWind( &tmp, &hitPt);
  115.  
  116.                                         /* Find part of control clicked in    */
  117.                                         /*   Note that a part code of zero    */
  118.                                         /*   means that the control is        */
  119.                                         /*   inactive, so we do nothing        */
  120.     whichPart = TestControl( macControl, hitPt);
  121.     
  122.     PenNormal();
  123.     
  124.     if (whichPart >= inThumb) {            /* Click inside moving indicator    */
  125.  
  126.         TrackThumb();                //  Different from CControl: Call TrackThumb()
  127.     
  128.     } else if (whichPart > 0) {            /* Click inside stationary part        */
  129.     
  130.         /* The parameter of -1L    means that the actionProc in the    */
  131.         /* Toolbox control record will be called continuously while    */
  132.         /* the mouse is down.  If actionProc is NULL, no additional    */
  133.         /* action is performed.                                        */
  134.  
  135.         if (TrackControl(macControl, hitPt, (ProcPtr)-1L))
  136.         
  137.                 /* TrackControl returns the part code if user    */
  138.                 /* executed a good click, i.e., the mouse was    */
  139.                 /* pressed and released in the same part. If so    */
  140.                 /* respond to the click; otherwise, do nothing.    */
  141.  
  142.             DoGoodClick(whichPart);
  143.     }
  144.     
  145. }    //==== CHyperScrollBar::DoClick() ====\\
  146.  
  147.  
  148.  
  149. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  150. //| CHyperScrollBar::TrackThumb
  151. //|
  152. //| Purpose: This is called when the thumb is clicked.  It tracks the mouse
  153. //|          and actively rotated the hypercube according to the mouse position.
  154. //|
  155. //| Parameters: none
  156. //|____________________________________________________________________________
  157.  
  158. void CHyperScrollBar::TrackThumb(void)
  159. {
  160.  
  161.     while(StillDown())
  162.         {
  163.         
  164.         Prepare();
  165.         
  166.         Point mouse_point;                        //  Find current mouse location
  167.         GetMouse(&mouse_point);
  168.         
  169.         LongRect frame;                            //  Find max and min locations of thumb
  170.         GetFrame(&frame);
  171.         short tracking_min = hEncl + 16 + 8;
  172.         short tracking_max = hEncl + frame.right - 16 - 8;
  173.         
  174.         if (mouse_point.h > tracking_max)        //  Pin mouse point to max and min locations
  175.             mouse_point.h = tracking_max;
  176.             
  177.         if (mouse_point.h < tracking_min)
  178.             mouse_point.h = tracking_min;
  179.             
  180.         short min = GetMinValue();                //  Find max and min scroll bar values
  181.         short max = GetMaxValue();
  182.     
  183.         short value = min +                        //  Compute scroll bar value correspinding to
  184.             (max - min)*                        //    current mouse location
  185.                 (mouse_point.h - tracking_min)/
  186.                     (tracking_max - tracking_min);
  187.     
  188.         SetValue(value);                        //  Change scroll bar value (and redraw hypercube)
  189.     
  190.         }
  191.  
  192. }    //==== CHyperScrollBar::TrackThumb() ====\\